package com.example.clothingmanager.controller;

import com.example.clothingmanager.bean.Clothes;
import com.example.clothingmanager.service.ClothesService;
import com.example.clothingmanager.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * @author Huangyt
 * @version 1.0
 * @date 2020/5/7 16:55
 */

@RestController
@RequestMapping("/clothes")
public class ClothesController {
    @Autowired
    ClothesService clothesService;

    @GetMapping("/list/{page}/{size}")
    public Page<Clothes> list(@PathVariable("page") int page, @PathVariable("size") int size, @RequestParam(value = "keyword", defaultValue = "")String keyword){
        System.out.println("进来了" + page + " " + size + " " + keyword);
        return clothesService.list(page, size, keyword);
    }

    @DeleteMapping("/del/{citem}")
    public Result delete(@PathVariable("citem")String citem){
        System.out.println("进入删除");
        return clothesService.delete(citem);
    }

    @GetMapping("/get/{citem}")
    public Result get(@PathVariable("citem")String citem){
        System.out.println("进入获取");
        return clothesService.get(citem);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Clothes clothes){
        System.out.println("进入更新");
        return clothesService.update(clothes);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Clothes clothes){
        System.out.println("进入添加");
        return clothesService.add(clothes);
    }

    @GetMapping("/clothesList")
    public Result clothesList(){
        return clothesService.clothesList();
    }

}
